home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / admin / linuxcon.000 / linuxcon / linuxconf-1.6 / dialog / varval.c < prev    next >
C/C++ Source or Header  |  1996-07-22  |  3KB  |  132 lines

  1. #include <string.h>
  2. #include "internal.h"
  3.  
  4. const int NB_VARVAL=20;
  5. static HTML_VARVAL *last[NB_VARVAL];
  6.  
  7.  
  8. /* #Specification: html mode / strategy / sub dialog
  9.     The system (linuxconf) loosely remember the last 20 POST it received.
  10.     Potentially a POST yields a sub-dialog. When receiving a POST,
  11.     linuxconf record de variable and copy those to the application
  12.     and return to it with the proper button (as per the POST). The
  13.     application when receiving an ACCEPT button will return to a
  14.     previous level (logical level of sub menu). Other button generally
  15.     yield to sub-dialog. In this case, linuxconf will draw the sub-dialog
  16.     and escape away to the main loop. The next time the user will post
  17.     into this sub-dialog, linuxconf will rewalk the path and cross
  18.     the previous post. At this point, the path will tell that this step
  19.     was indeed a POST and linuxconf will reactivate the variable collected
  20.     from the original POST and return the original button. This should
  21.     recreate the situation yielding to the sub-dialog.
  22.  
  23.     This is why old variable-values from old POST have to be remember.
  24. */
  25. #
  26. /*
  27.     An HTML_VARVAL hold the content of a POST. It remember the
  28.     path and the value of the different variables recover.
  29.  
  30. */
  31. PUBLIC HTML_VARVAL::HTML_VARVAL (const char *key)
  32. {
  33.     context.setfrom (key);
  34.     delete last[NB_VARVAL-1];
  35.     memmove (last,last+1,(NB_VARVAL-1)*sizeof(HTML_VARVAL*));
  36.     last[0] = this;
  37. }
  38.  
  39. /*
  40.     Add a value pair (varible/value) to the list
  41. */
  42. PUBLIC void HTML_VARVAL::add (const char *var, const char *val)
  43. {
  44.     vars.add (new SSTRING (var));
  45.     vals.add (new SSTRING (val));
  46. }
  47.  
  48.  
  49. /*
  50.     Return the number of variables in the table
  51. */
  52. PUBLIC int HTML_VARVAL::getnb()
  53. {
  54.     return vars.getnb();
  55. }
  56.  
  57. /*
  58.     Return the value of a variable or "" if it is not there
  59. */
  60. PUBLIC const char *HTML_VARVAL::getval(const char *var)
  61. {
  62.     const char *ret = "";
  63.     int n = vars.getnb();
  64.     for (int i=0; i<n; i++){
  65.         if (vars.getitem(i)->cmp(var)==0){
  66.             ret = vals.getitem(i)->get();
  67.             break;
  68.         }
  69.     }
  70.     return ret;
  71. }
  72. /*
  73.     Return the value of a variable
  74. */
  75. PUBLIC const char *HTML_VARVAL::getval(int no)
  76. {
  77.     return vals.getitem(no)->get();
  78. }
  79. /*
  80.     Return the name of a variable
  81. */
  82. PUBLIC const char *HTML_VARVAL::getvar(int no)
  83. {
  84.     return vars.getitem(no)->get();
  85. }
  86. /*
  87.     Return != 0 if a given variable do exist in this list.
  88. */
  89. PUBLIC int HTML_VARVAL::exist(const char *var)
  90. {
  91.     int ret = 0;
  92.     int n = vars.getnb();
  93.     for (int i=0; i<n; i++){
  94.         if (vars.getitem(i)->cmp(var)==0){
  95.             ret = 1;
  96.             break;
  97.         }
  98.     }
  99.     return ret;
  100. }
  101. /*
  102.     Return the context of the object.
  103. */
  104. PUBLIC const char *HTML_VARVAL::getcontext()
  105. {
  106.     return context.get();
  107. }
  108.  
  109.  
  110. /*
  111.     Get the HTML_VARVAL for a given context
  112.     Return NULL if not found.
  113. */
  114. HTML_VARVAL *varval_get (const char *key)
  115. {
  116.     HTML_VARVAL *ret = NULL;
  117.     for (int i=0; i<NB_VARVAL; i++){
  118.         HTML_VARVAL *h = last[i];
  119.         if (h != NULL && strcmp(key,h->getcontext())==0){
  120.             ret = h;
  121.             if (i != 0){
  122.                 memmove (last,last+1,i*sizeof(HTML_VARVAL*));
  123.                 last[0] = h;
  124.             }
  125.             break;
  126.         }
  127.     }
  128.     return ret;
  129. }
  130.             
  131.  
  132.